package com.jjb.www.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.layout.ShapeLinearLayout;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.AnsweringDetailsApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.utils.ReplaceUtils;

/**
 * author : Android CRG
 * github : https://github.com/getActivity/AndroidProject
 * time   : 2018/11/05
 * desc   : 可进行拷贝的副本
 */
public final class AansweringDetails2Adapter extends AppAdapter<AnsweringDetailsApi.Bean.QuestionAnswerDTO> {
    public AansweringDetails2Adapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeLinearLayout mLlItem;
        private ShapeTextView mTvTitle;
        private ShapeImageView mImgType;


        private ViewHolder() {
            super(R.layout.item_answering_details2);
            mLlItem = findViewById(R.id.ll_item);
            mTvTitle = findViewById(R.id.tv_title);
            mImgType = findViewById(R.id.img_type);
            setIsRecyclable(false);
        }

        @Override
        public void onBindView(int position) {
            AnsweringDetailsApi.Bean.QuestionAnswerDTO bean = getItem(position);
            mTvTitle.setText(bean.getOption());
            if (!"".equals(getTag())) {
                String[] temp = null;
                temp = getTag().toString().split(",");
                for (String str : temp) {
                    if (str.equals(String.valueOf(bean.getSort()))) {
                        mLlItem.getShapeDrawableBuilder()
                                .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_EAF1FE))
                                .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_3675FE))
                                .setStrokeWidth(1)
                                .intoBackground();
                    } else {

//                        mLlItem.getShapeDrawableBuilder()
//                                .setSolidColor(ContextCompat.getColor(getContext(), R.color.white))
//                                .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_DCDCDC))
//                                .setStrokeWidth(1)
//                                .intoBackground();
                    }
                }

            } else {
                mLlItem.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.white))
                        .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_DCDCDC))
                        .setStrokeWidth(1)
                        .intoBackground();
            }
            if (bean.getIs_true() == 1) {
                GlideApp.with(getContext())
                        .load(R.mipmap.icon_dt_yes)
                        .into(mImgType);
            } else {
                GlideApp.with(getContext())
                        .load(R.mipmap.icon_dt_no)
                        .into(mImgType);
            }

        }
    }
}